import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;

    public MyStack() {
        this.elem = new int[5];
    }

    public void push(int val) {
        if(isFull()) {
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize++] = val;
    }


    public boolean isFull() {
        return usedSize == elem.length;
    }

    //删除栈顶元素
    public int pop() {
        //判断栈是否为空
        if(empty()) {
            //抛出异常
            throw new StackEmptyException("栈为空！");
        }
        //开始删除
        return elem[--usedSize];
    }


    public int peek() {
        if(empty()) {
            throw new StackEmptyException("栈为空!");
        }

        return elem[usedSize-1];
    }

    public boolean empty() {
        return usedSize == 0;
    }


}
